package com.ch.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @program: 123start
 * @description:
 * @author: chenhang
 * @create: 2023-02-19 20:43
 */

/**
 * 1.继承 ==> 身份
 *      自定义Servlet
 *          ==>HttpServlet   专用于http协议的 servlet
 *              ==>GenericServlet  通用servlet ==> 应用到所有的协议,http,ftp...
 *                  ==>Servlet,ServletConfig(配置接口)
 * 2 实现(覆盖) ==> 业务
 *       实现doXXX 方法： doGet 和 doPost 是最常用的
 * 3.配置 ==> 安装
 */
@WebServlet("/getWeek")
public class GetWeekServlet extends HttpServlet {
    private int a=0;
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        a++;
        Date date = new Date();
        String mask = req.getParameter("mask");
        if (mask == null) {
            mask = "EEE";
        }
        SimpleDateFormat sdf = new SimpleDateFormat(mask);
        String format = sdf.format(date);
        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().printf("第%d次访问： "+a);
        resp.getWriter().print(format);
    }
}
